﻿function showHideDIVAdv() {
    /* Commanded by 'Imran Gani' on 12-Jul-13, to use Jquery.
    if (document.getElementById("div_advanced").style.display == "block")
    {
    document.getElementById("div_advanced").style.display = "none";
    document.getElementById("img_advanced").src = "Images/expand3.gif";            
    }
    else
    {
    document.getElementById("div_advanced").style.display = "block";
    document.getElementById("img_advanced").src = "Images/collapse3.gif";
    }*/
    if ($("#div_advanced").is(":hidden")) // Added by 'Imran Gani' on 12-Jul-13, to use Jquery.
    {
        $("#img_advanced").attr("title", "Click to collapse");
        $("#div_advanced").slideDown();
        $("#img_advanced").attr("src", "Images/collapse3.gif");
    }
    else {
        $("#img_advanced").attr("title", "Click to expand");
        $("#div_advanced").slideUp();
        $("#img_advanced").attr("src", "Images/expand3.gif");
    }
}
function showLoad(arg) {
    try {
        Page_ClientValidate('');
        if (Page_IsValid == false) return;
        if (arg == true)
            document.getElementById("ctl00_ContentPlaceHolder3_lblStatusUpload").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Processing...";
        else
            document.getElementById("ctl00_ContentPlaceHolder3_lblStatusUpload").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Processing...";
    }
    catch (Ex) { }
}
function DeleteImportedRecords(af_row_id) {
    if (confirm('Are you sure you want to delete all records inserted in this import?')) {
        if (document.getElementById("ctl00_ContentPlaceHolder3_img_del_" + af_row_id) != null) {
            document.getElementById("ctl00_ContentPlaceHolder3_img_del_" + af_row_id).src = "Images/load.GIF";
        }
        var id = "ctl00_ContentPlaceHolder3_hfdeleteclick";
        if (document.getElementById(id) != null)
            document.getElementById(id).value = "1";

        ResetMessage();
        if (document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics") != null)
            document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics").style.display = "block";
    }
    else
        return false;
}
function showHideStats() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics").style.display == "block")
        document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics").style.display = "none";
    else
        document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics").style.display = "block";
}
function ResetMessage() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_lblStatusUpload") != null)
        document.getElementById("ctl00_ContentPlaceHolder3_lblStatusUpload").innerHTML = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_lbl_message") != null)
        document.getElementById("ctl00_ContentPlaceHolder3_lbl_message").innerHTML = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics") != null)
        document.getElementById("ctl00_ContentPlaceHolder3_pnlStatistics").style.display = "none";

}
// Commented by Bala for hiding the link labels on 18 July 2012
// function ClearDownloadTemplate()
// {
//    if(document.getElementById("ctl00_ContentPlaceHolder3_lblTemplateLink")!=null)
//            document.getElementById("ctl00_ContentPlaceHolder3_lblTemplateLink").innerHTML = "";
// }
function ClearDownloadTemplate() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_lblXLSLink") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_lblXLSLink").innerHTML = "";
        document.getElementById("ctl00_ContentPlaceHolder3_lblCSVLink").innerHTML = "";
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_lblCSVLink") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_lblXLSLink").innerHTML = "";
        document.getElementById("ctl00_ContentPlaceHolder3_lblCSVLink").innerHTML = "";
    }
}

function checkExtension() {
    var hash = { '.xls': 1, '.xlsx': 2, '.xlsm': 3, '.xlsb': 4, '.csv': 5 };
    var filename = "";
    if (document.getElementById("ctl00_ContentPlaceHolder3_FileUpload1") != null) {
        filename = document.getElementById("ctl00_ContentPlaceHolder3_FileUpload1").value;

        if (filename.trim() != "") {
            var re = /\..+$/;
            var ext = filename.match(re);
            if (hash[ext]) {
                return true;
            }
            else {
                alert("Invalid file, Please select files with extensions, .xls, .xlsx or csv");
                ClearFileUpload();
                return false;
            }
        }
        else {
            alert("Invalid file, Please select files with extensions, .xls, .xlsx or csv");
            return false;
        }
    }
}

function ClearFileUpload() {
    try {
        //var who=document.getElementsByName("ctl00_ContentPlaceHolder3_FileUpload1")[0];
        var who = null;
        who = document.getElementById("ctl00_ContentPlaceHolder3_FileUpload1")[0];
        try {
            who.value = "";
        }
        catch (exp) {
            who = document.getElementsByName("ctl00$ContentPlaceHolder3$FileUpload1")[0];
            who.value = "";
        }
        var who2 = who.cloneNode(false);
        who2.onchange = who.onchange;
        who.parentNode.replaceChild(who2, who);
    }
    catch (exp) { }
}

// Added by 'Imran Gani' on 30-Jul-2013, to get object related fields for avoiding duplicates during import.
function getRaletedFields() {
    try {
        var ObjID = $("#ctl00_ContentPlaceHolder3_p_simple_import_target_object").val();
        $("#avoid_duplicates_err").html("");
        $.ajax({
            url: "mb_ajaxhandler.aspx?action=import_Obj_fields&val=" + ObjID,
            cache: false,
            dataType: "json",
            beforeSend: function () { $("#avoid_duplicates_err").html("<img src=\"Images/load.gif\" style=\"width:15px;Padding-top:3;\">"); },
            success: function (resp) {
                if (resp != null && resp.length > 0) {
                    var fldValues = document.getElementById("ctl00_ContentPlaceHolder3_p_simple_import_avoid_duplicates_based_on");
                    if (fldValues != null)
                        fldValues.options.length = 0;
                    for (var i = 0; i < resp.length; i++) {
                        fldValues.options[i] = new Option(resp[i]["label"], resp[i]["id"]);
                    }
                }
                else {
                    document.getElementById("ctl00_ContentPlaceHolder3_p_simple_import_avoid_duplicates_based_on").options.length = 0;
                    $("#avoid_duplicates_err").html("Unable to retrive fields. <a href=\"#\" style=\"color:Blue;\" onclick=\"javascript:getRaletedFields('" + ObjID + "'); return false;\">Try Again</a>");
                }
            },
            complete: function () { $("#avoid_duplicates_err").html(""); },
            error: function (resp) {
                document.getElementById("ctl00_ContentPlaceHolder3_p_simple_import_avoid_duplicates_based_on").options.length = 0;
                $("#avoid_duplicates_err").html("Unable to retrive fields. <a href=\"#\" style=\"color:Blue;\" onclick=\"javascript:getRaletedFields('" + ObjID + "'); return false;\">Try Again</a>");
            }
        });
    }
    catch (err) {}
}